<template>
  <section class="sample-section"  v-loading.lock="loading" element-loading-text="拼命加载中">
    <el-form :model="dataForm" @keyup.enter.native="getDataList()" label-width="80px">
      <el-row :gutter="10">
        <el-col :xs="24" :sm="24" :md="12" :lg="4" :xl="4">
          <el-form-item label="收款姓名" prop="batch_number">
            <el-input v-model="dataForm.pay_name" type="text" placeholder="收款姓名" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="4" :xl="4">
          <el-form-item label="结算金额" prop="batch_number">
            <el-input v-model="dataForm.settle_money" type="text" placeholder="结算金额 0-1000" clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="付款时间" prop="sale">
            <el-date-picker
              v-model="dataForm.pay_time"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              :picker-options="pickerOptions">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :xs="20" :sm="20" :md="12" :lg="6" :xl="6">
          <el-form-item>
            <el-button type="primary" @click="getDataList()">查询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-card class="box-card">
      总支付金额： <span class="danger-text">{{totalInfo.total_pay_money | numFilter}} （元）</span>总结算金额：<span class="danger-text">{{totalInfo.total_settle_money | numFilter}}</span> （元）总服务费： <span class="danger-text"> {{totalInfo.total_pay_money - totalInfo.total_settle_money | numFilter}}</span> （元）
    </el-card>
    <el-table
      :data="dataList"
      border
      :row-class-name="rowClassName"
      v-loading="dataListLoading"
      @sort-change="changeSort"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        width="80"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="pay_name"
        header-align="center"
        align="center"
        label="收款姓名">
      </el-table-column>
      <el-table-column
        prop="pay_type"
        header-align="center"
        align="center"
        label="支付类型">
      </el-table-column>
      <el-table-column
        prop="pay_amount"
        header-align="center"
        align="center"
        label="收款账号">
      </el-table-column>
      <el-table-column
        prop="pay_money"
        header-align="center"
        align="center"
        label="支付金额">
          <template slot-scope="scope">
            <span>{{scope.row.pay_money | numFilter}}</span>
          </template>
      </el-table-column>
      <el-table-column
        prop="settle_money"
        header-align="center"
        align="center"
        label="结算金额">
        <template slot-scope="scope">
          <span>{{scope.row.settle_money | numFilter}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="pay_time"
        header-align="center"
        align="center"
        width="180"
        label="付款时间">
      </el-table-column>
      <el-table-column
        prop="created_at"
        header-align="center"
        align="center"
        width="180"
        label="导入时间">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100, 500, 1000, 2000, 5000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </section>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          pay_name: '',
          pay_time: '',
          settle_money: '',
          sort_by: '',
          order_by: ''
        },
        totalInfo: {
          total_pay_money: 0,
          total_settle_money: 0
        },
        loading: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        }
      }
    },
    components: {
    },
    activated () {
      this.getDataList()
    },
    methods: {
      rowClassName({row, rowIndex}) {
        if(row.is_jg) {
          return 'bgred';
        }
        return ''
      },
      changeSort(val) {
        if (val.order !== null) {
          this.dataForm.sort_by = val.prop
          this.dataForm.order_by = val.order === 'ascending' ? 'asc' : 'desc'
        } else {
          this.dataForm.sort_by = ''
          this.dataForm.order_by = ''
        }
        this.dataListLoading = true
        this.getCustomerList()
        this.dataListLoading = false
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.getCustomerList()
        this.dataListLoading = false
      },
      getCustomerList() {
        this.$http({
          url: this.$http.adornUrl('/member/statistic/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'pay_name': this.dataForm.pay_name,
            'pay_time': this.dataForm.pay_time,
            'settle_money': this.dataForm.settle_money,
            'sort': this.dataForm.sort_by,
            'order': this.dataForm.order_by
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
            this.totalInfo = data.page.totalInfo
          } else {
            this.dataList = []
            this.totalPage = 0
            this.$message.error(data.msg)
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      jumpTourl ( _url, _id) {
        this.$router.push({ name: _url, query: { id:  _id}})
      },
    },
    filters: {
      // 截取当前数据到小数点后两位
      numFilter(value) {
        const realVal = parseFloat(value).toFixed(2);
        return realVal;
      }
    }
  }
</script>

<style lang="scss">
  .bgred {
    background-color: #fab6b6 !important;
  }
</style>
